package com.lichongbing.lyoggl.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lichongbing.lyoggl.model.JwtUser;
import com.lichongbing.lyoggl.model.LyogglUsers;
import com.lichongbing.lyoggl.service.LyogglUsersService;
import com.lichongbing.lyoggl.mapper.LyogglUsersMapper;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 *
 */
@Service
public class LyogglUsersServiceImpl extends ServiceImpl<LyogglUsersMapper, LyogglUsers> implements UserDetailsService,LyogglUsersService{
    @Resource
    private LyogglUsersMapper mapper;

    @Override
    public Page<LyogglUsers> selectPage(Page<LyogglUsers> page, LambdaQueryWrapper<LyogglUsers> orderByAsc) {
        return mapper.selectPage(page,orderByAsc);
    }

    @Override
    public UserDetails loadUserByUsername(String userid) throws UsernameNotFoundException {
        LyogglUsers user =   mapper.findByUsername(userid);

        return new JwtUser(user);
    }

    @Override
    public LyogglUsers getLyogglUsersById(String userid) {

        LyogglUsers user =   mapper.findByUsername(userid);
        return user;
    }

    @Override
    public boolean isToken(String userid) {
        String isToken = mapper.isToken(userid);
        if(isToken.equals("1")){
            return  true;
        }else{
            return false;
        }

    }
    @Override
    public String getPushToken(String userid) {
      String pushToken = mapper.getPushToken(userid);
      if(pushToken==null){
          return "111111111";
      }else {
          return pushToken;
      }
    }

    @Override
    public int getConfiguration() {

        return  mapper.getConfiguration();
    }
}
